%option yylineno
%{
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "mystruct.h"
    #include "y.tab.h"
%}

id [a-zA-Z_][a-zA-Z0-9_]*
Digit [0-9]
Floating [0-9]+\.[0-9]+
%%
"PROGRAM"  return PROGRAM;
"VAR"      return VAR;
"ENDVAR"   return ENDVAR;
"INTEGER"  return INTEGER;
"REAL"	   return REAL;
"CHAR"     return CHAR;
"BEGIN"    return BEGINRE;
"READ"     return READ;
"WRITE"    return WRITE;
"WRITESP"  return WRITESP;
"WRITELN"  return WRITELN;
"END"      return END;
"OR"	   return OR;
"AND"	   return AND;
"NOT"      return NOT;
"IF"	   return IF;
"ELSE"     return ELSE;
"THEN"     return THEN;
"ENDIF"	   return ENDIF;
"ARRAY"    return ARRAY;
"OF"	   return OF;
"FOR"	   return FOR;
"TO"       return TO;
"DOWNTO"   return DOWNTO;
"DO"       return DO;
"WHILE"    return WHILE;
"PROCEDURE" return PROCEDURE;
"FUNCTION"  return FUNCTION;
"CASE"   return SWITCH;
"OTHERWISE" return OTHERWISE;
"ENDCASE"  return ENDCASE;

{Floating} {
	     yylval.sValue = strdup(yytext);
	     return FLOAT;
	   }
{id}       {
	     yylval.sValue = strdup(yytext);
 	     return ID;
	   }
{Digit}+   {
	     yylval.sValue = strdup(yytext);
	     return NUM;
	   }
\'(.|(\\.))\'  {
		char* str = strdup(yytext);
		int length = strlen(str);
		if(length==3)
		{
		    yylval.cValue = (int)(str[1]);
		}
		else if(length==4&&str[1]=='\\')
		{
		    if(str[2]=='n')
		    {
			yylval.cValue = '\n';
		    }
		    else if(str[2]=='t')
		    {
			yylval.cValue = '\t';
		    }
		}
		return CHAR_LITERAL;
	   }
".."       return RANGEFROMTO;
":="	   return ASSIGN;
";"        return(59);
":"        return(58);
","        return(44);
"+"        return(43);
"-"        return(45);
"*"        return(42);
"/"        return(47);
"("        return(40);
")"        return(41);
">"	   return GREATERTHAN;
"<"	   return LESSTHAN;
">="	   return GREATERTHANEQ;
"<="	   return LESSTHANEQ;
"="	   return EQUAL;
"<>"       return NOTEQUAL;
"%%"       {comment();}
[ \t\f\r\v\n] {;}
"["        return(91);
"]"	   return(93);
%%

comment()
{
	register int c;
	while( (c=input() != '\n') );
}
